﻿using Model.Modules;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.TextFormatting;
using System.Windows.Shapes;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;

namespace SteelDetection
{
    /// <summary>
    /// DefectTypeDlg.xaml 的交互逻辑
    /// </summary>
    public partial class DefectTypeDlg : Window
    {
        public DefectTypeDlg()
        {
            InitializeComponent();
            initDlg();
        }
        

        public DefectTypeDlg(double type)
        {
            InitializeComponent();
            initDlg();
            var matchitems = (typelist.ItemsSource as List<defect_type>).Where(t => t.id == type);
            if (matchitems.Count() == 1)
            {
                typelist.SelectedIndex = (typelist.ItemsSource as List<defect_type>).IndexOf(matchitems.First());
            }
                

        }

        public void initDlg() {
            this.WindowStartupLocation = WindowStartupLocation.Manual;
            var mouseX= System.Windows.Forms.Control.MousePosition.X;
            this.Left = SystemParameters.FullPrimaryScreenWidth - mouseX > 570 ? mouseX : mouseX - 570;
            var mouseY = System.Windows.Forms.Control.MousePosition.Y;
            this.Top = SystemParameters.FullPrimaryScreenHeight-mouseY > 370? mouseY: mouseY-370;
            Dtype = -1;
        }

        public int Dtype { get; set; }

        private void typelist_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Dtype = (typelist.SelectedItem as defect_type).id;
            if (Dtype != -1)
            {
                btn_ok.IsEnabled = true;
            }
            else
            {
                btn_ok.IsEnabled = false;
            }
        }

        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            Close();
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            Close();
        }

    }



}
